package com.aaa.car.service.impl;

import com.aaa.car.dao.ViolationRecordDao;
import com.aaa.car.entity.ViolationRecord;
import com.aaa.car.service.ViolationRecordService;
import com.aaa.common.constant.ReturnCode;
import com.aaa.common.util.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 违章记录表(ViolationRecord)表服务实现类
 *
 * @author makejava
 * @since 2020-11-23 19:06:48
 */
@Service("violationRecordService")
public class ViolationRecordServiceImpl implements ViolationRecordService {
    @Resource
    private ViolationRecordDao violationRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ViolationRecord queryById(Integer id) {
        return this.violationRecordDao.queryById(id);
    }

    @Override
    public Result queryViolationRecord(Integer pageNo, Integer pageSize, ViolationRecord violationRecord) {
        //分页
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<ViolationRecord> pageInfo = new PageInfo<ViolationRecord>(violationRecordDao.queryAll(violationRecord));
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),pageInfo);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ViolationRecord> queryAllByLimit(int offset, int limit) {
        return this.violationRecordDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param violationRecord 实例对象
     * @return 实例对象
     */
    @Override
    public ViolationRecord insert(ViolationRecord violationRecord) {
        this.violationRecordDao.insert(violationRecord);
        return violationRecord;
    }

    /**
     * 修改数据
     *
     * @param violationRecord 实例对象
     * @return 实例对象
     */
    @Override
    public ViolationRecord update(ViolationRecord violationRecord) {
        this.violationRecordDao.update(violationRecord);
        return this.queryById(violationRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.violationRecordDao.deleteById(id) > 0;
    }
}